<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>用户注册</title>

    <link rel="icon" type="image/png" href="img/toplogo.png" />
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="font-awesome/css/font-awesome.css" rel="stylesheet">

    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    
    <link rel="stylesheet" type="text/css" href="css/sweetalert.css">

    <!-- Mainly scripts -->
    <script src="js/jquery-2.1.1.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/trim.js"></script>
    
    <script src="js/sweetalert.min.js"></script>

    <script type="text/javascript">

      // $(function(){
      //     $.ajax({
      //         url:"common/getUserInfo.php",
      //         dataType:"json",
      //         success:function(data){
      //           // console.log(data.userid);
      //           var data = data.userid; 
      //           //console.log(data.userid);
                
      //             if(data==undefined || data=="" || data==null )
      //           {
      //             location.href="login.html";
      //           }
      //         }
      //     })
      // })
    
      $(function(){//文档加载结束
        $("#register").click(function(){
          if($("#userid").val()==""||$("#password").val()==""||$("#username").val()=="")
          {
            swal("", "请确认信息的完整!", "error");
            //alert("请确认信息的完整");
            return;
          }
          if($("#password").val()!=$("#password2").val())
          {
            swal("", "两次密码不一样，请重新输入！", "error");
            return;
          }
          
          $.ajax({
              url:"common/register.php",
              type:"post",
              data:{
                userid:$("#userid").val().trim(),
                password:$("#password").val().trim(),
                username:$("#username").val().trim()
              },
              success:function(msg){
                //console.log(msg);
                if(msg=="0"){
                  //alert("");
                  swal("", "注册失败！", "error");
                }
                if(msg=="1"){
                  //alert("注册成功！");
                  swal("", "注册成功！", "success");
                  location.href="login.html";
                  
                }
                if(msg=="-1"){
                  //alert("用户名已经存在！");
                  swal("", "用户名已经存在！", "error");
                }
              },
            })
          });    
        });

</script> 

</head>

<body class="gray-bg">

    <div class="middle-box text-center loginscreen animated fadeInDown">
        <div>
            <div>

                <h1 class="logo-name">注</h1>

            </div>
            <h3>用户注册</h3>

                <div class="form-group">
                    <input type="text" class="form-control" name="userid" id="userid" placeholder="账号" required="">
                </div>
                <div class="form-group">
                    <input type="password" class="form-control" name="password" id="password" placeholder="密码" required="">
                </div>
                <div class="form-group">
                    <input type="password" class="form-control" name="password2" id="password2" placeholder="确认密码" required="">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" name="username" id="username" placeholder="用户名" required="">
                </div>
                <button type="submit" id="register" class="btn btn-primary block full-width m-b">注册</button>
        </div>
    </div>

    

</body>

</html>
